<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const o = { name: "laowang" };

      //   参数一  继承
      const o1 = Object.create(null);
      console.log("o1", o1);

      const o2 = Object.create(o);
      console.log("o2", o2);

      //   参数二 创造属性
      const o3 = Object.create(null, {
        name: {
          value: "laowang", //属性值
          writable: false, //是否可写
          enumerable: false, //是否可枚举
          configurable: false, //是否可以删除或者修改配置
        },
        age: {
          value: 12,
        },
      });

      //   添加属性 Object.defineProperty
      Object.defineProperty(o3, "sex", {
        value: "男",
        writable: true,
        configurable: true,
        enumerable: true,
      });
      console.log("o3", o3);

      //   存取器属性
      const o4 = Object.create(null, {
        firstName: {
          value: "lao",
          writable: true,
        },
        lastName: {
          value: "p",
          writable: true,
        },
      });

      Object.defineProperty(o4, "fullName", {
        get() {
          return this.firstName + " " + this.lastName;
        },

        set(value) {
          console.log(value);
          const [firstName, lastName] = value.split(" ");
          this.firstName = firstName;
          this.lastName = lastName;
        },
      });

      console.log("o4", o4);
      console.log("o4.fullname", o4.fullName);
      o4.fullName = "xiao p";
      //   console.log("o4", o4);
    </script>
  </body>
</html>
